package edu.gdkm.dao;

import edu.gdkm.pojo.Person;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface PersonDAO {
    @Select("select * from tb_person where id = #{id}")
    @Results(id = "personMap", value = {
            @Result(property = "idCard", column = "idcard_id", one = @One(select = "edu.gdkm.dao.IdCardDAO.findById"))
    })
    Person findById(Integer id);
    @Select("select * from tb_person")
    @ResultMap("personMap")
    List<Person> findAll();
    @Insert("insert into tb_person(name, sex, birthday, address, id_card_id) values(#{name}, #{sex}, #{birthday}, #{address}, #{idCard.id})")
    boolean save(Person person);
    @Update("update tb_person set name = #{name}, sex = #{sex}, birthday = #{birthday}, address = #{address}, idcard_id = #{idCard.id} where id = #{id}")
    boolean update(Person person);
    @Delete("delete from tb_person where id = #{id}")
    boolean delete(Integer id);
}
